package 优先算法.滑动窗口.长度最小的子数组;

public class Teacher {

}
class Solution2 {
    public int minSubArrayLen(int target, int[] nums) {
        int n=nums.length,len=Integer.MAX_VALUE,sum=0;

        for(int left=0,right=0;right<n;right++){
            //进窗口
            sum+=nums[right];
            //判断
            while(sum>=target){
                len=Math.min(len,right-left+1);
                //出窗口
                sum-=nums[left++];
            }
        }
        return len==Integer.MAX_VALUE? 0 : len;
    }
}